<?php
session_start();
?>
<?php
$ten_dn = $_SESSION['ten_dn'];
include("../connect.php");
$sql = "SELECT *, 
				DATE_FORMAT(ngay_dang, '%d-%m-%Y %H:%i:%s') AS ngay, 
				DATE_FORMAT(DATE_ADD(ngay_dang, INTERVAL thoi_gian_song DAY), '%d-%m-%Y %H:%i:%s') AS ngay_hh 
		FROM mau_tin_rv 
		WHERE ten_dn = '$ten_dn' 
		ORDER BY ngay_dang DESC";
$rs = mysql_query($sql);
?>
<form name="ds_mau_tin_cn">
<table class="table" cellpadding="2" cellspacing="0" width="100%">
	<tr>
    	<td colspan="8"><h2><b>Danh sách mẩu tin rao vặt của bạn</b></h2></td>
    </tr>
    <tr>
    	<td class="title_left">STT</td>
        <td class="title_row">TIÊU ĐỀ</td>
        <td class="title_row">NGÀY ĐĂNG</td>
        <td class="title_row">NGÀY HẾT HẠN</td>
        <td class="title_row">TRẠNG THÁI</td>
        <td class="title_row"><font color="#00FF00">Sửa</font></td>
        <td class="title_row"><font color="#FF0000">Xóa</font></td>
        <td class="title_row"></td>
    </tr>
<?php
$i = 0;
while($row = mysql_fetch_array($rs)){
	$i++;
	$ms_mt = $row[0];
	$tieu_de = $row[3];
	$ngay_dang = $row['ngay'];
	$ngay_hh = $row['ngay_hh'];
	$vip = $row[9];
	$so_lan_xem = $row[10];
	$giay_phep = $row[11];
?>
	<tr>
    	<td class="stt"><?php echo $i ?></td>
        <td class="data_row">
			<?php 
				echo $tieu_de;
				if($vip == 1) echo '<font color="#FF0000"><strong>-VIP-</strong></font>';
				echo '('.$so_lan_xem.' lượt xem)';
			?>
        </td>
        <td class="data_row"><?php echo $ngay_dang ?></td>
        <td class="data_row"><?php echo $ngay_hh ?></td>
        <td class="data_row">
        	<?php
				$sql1 = "SELECT * 
						 FROM mau_tin_rv 
						 WHERE ms_mau_tin_rv = '$ms_mt' 
						 AND DATE_ADD(ngay_dang, INTERVAL thoi_gian_song DAY) < NOW()";
				$rs1 = mysql_query($sql1);
				if(mysql_num_rows($rs1) > 0){
					echo "<font color='#FF0000'>Hết hạn</font>";	
				}
				else{
					if($giay_phep == 0){
						echo "<font color='#FF9900'>Chưa được đăng</font>";	
					}
					else echo "<font color='#009900'>Đang được đăng</font>";
				}
			?>
        </td>
        <td class="data_row"><a onclick="capNhat_tin_cn('<?php echo $ms_mt ?>')"><img src="images/edit.gif" border="0" /></a></td>
        <td class="data_row"><a onclick="xoa('<?php echo $ms_mt ?>')"><img src="images/Delete.png" border="0" width="17px" height="17px"/></a></td>
        <td class="data_row"><input type="checkbox" name="chkxoa" value="<?php echo $ms_mt ?>" /></td>
    </tr>
<?php
}
?>
	<tr>
  		<td height="20" align="center" colspan="8"><b>Tổng số mẩu tin: <?php echo mysql_num_rows($rs) ?></b></td>
  	</tr>
</table><br />
<div align="center">
<input type="button" name="them" id="them" value=" Thêm tin rao vặt " onclick="location.href='index.php?noidung=dtrv'" class="button"/>&nbsp;&nbsp;&nbsp;&nbsp;
<input type="button" name="them_" id="them_" value=" Thêm tin VIP " onclick="location.href='index.php?noidung=dtvip'" class="button"/>&nbsp;&nbsp;&nbsp;&nbsp;
<input type="button" name="xoa" id="xoa" value=" Xóa " onclick="thuchienxoa()" class="button"/>
</div>
</form>
<form name="frmDLxoa" action="thanh_vien/xl_xoa_mau_tin_cn.php" method="post">
<input type="hidden" name="ms_mt" value=""/>
</form>